using System.Xml;
using Oracle.ManagedDataAccess.Types;

namespace OracleInternal.ServiceObjects
{
	internal class OraXmlTypeData
	{
		internal char[] m_xmlChars;

		internal string m_xmlStr;

		internal OracleClob m_xmlClob;

		internal XmlDocument m_xmlDocInternal;

		internal OraXmlBlobWithText m_xmlBlobText;

		internal int m_csid;

		internal byte[] m_xmlLobLocator;

		internal OracleBlob m_xmlBlobCSX;

		internal TypeOfXmlData m_typeOfXmlData;

		internal OraXmlTypeData()
		{
		}

		internal OraXmlTypeData(TypeOfXmlData typeOfXmlData, object value)
		{
			m_typeOfXmlData = typeOfXmlData;
			switch (m_typeOfXmlData)
			{
			case TypeOfXmlData.String:
				m_xmlStr = (string)value;
				m_typeOfXmlData = TypeOfXmlData.String;
				break;
			case TypeOfXmlData.Chars:
				m_xmlChars = (char[])value;
				m_typeOfXmlData = TypeOfXmlData.Chars;
				break;
			case TypeOfXmlData.XmlDoc:
				m_xmlStr = ((XmlDocument)value).OuterXml;
				m_typeOfXmlData = TypeOfXmlData.String;
				break;
			case TypeOfXmlData.Clob:
				m_xmlClob = (OracleClob)((OracleClob)value).Clone();
				m_typeOfXmlData = TypeOfXmlData.Clob;
				break;
			case TypeOfXmlData.BlobWithText:
				m_xmlBlobText = ((OraXmlBlobWithText)value).Clone();
				m_typeOfXmlData = TypeOfXmlData.BlobWithText;
				break;
			case TypeOfXmlData.BlobCSX:
				m_xmlBlobCSX = (OracleBlob)((OracleBlob)value).Clone();
				m_typeOfXmlData = TypeOfXmlData.BlobCSX;
				break;
			}
		}

		internal void Dispose()
		{
			switch (m_typeOfXmlData)
			{
			case TypeOfXmlData.String:
			case TypeOfXmlData.StringAndXmlDoc:
				m_xmlStr = null;
				m_xmlDocInternal = null;
				break;
			case TypeOfXmlData.Chars:
				m_xmlChars = null;
				break;
			case TypeOfXmlData.XmlDoc:
				m_xmlDocInternal = null;
				break;
			case TypeOfXmlData.Clob:
			case TypeOfXmlData.ClobAndString:
				m_xmlClob.Dispose();
				m_xmlClob = null;
				m_xmlStr = null;
				break;
			case TypeOfXmlData.BlobWithText:
			case TypeOfXmlData.BlobWithTextAndString:
				m_xmlBlobText.Dispose();
				m_xmlBlobText = null;
				m_xmlStr = null;
				break;
			case TypeOfXmlData.BlobCSX:
			case TypeOfXmlData.BlobCSXAndString:
				m_xmlBlobCSX.Dispose();
				m_xmlBlobCSX = null;
				m_xmlStr = null;
				break;
			}
			m_typeOfXmlData = TypeOfXmlData.NoData;
		}

		internal OraXmlTypeData Clone()
		{
			OraXmlTypeData oraXmlTypeData = new OraXmlTypeData();
			switch (m_typeOfXmlData)
			{
			case TypeOfXmlData.String:
			case TypeOfXmlData.StringAndXmlDoc:
				oraXmlTypeData.m_xmlStr = m_xmlStr;
				oraXmlTypeData.m_typeOfXmlData = TypeOfXmlData.String;
				break;
			case TypeOfXmlData.Chars:
				oraXmlTypeData.m_xmlChars = m_xmlChars;
				oraXmlTypeData.m_typeOfXmlData = TypeOfXmlData.Chars;
				break;
			case TypeOfXmlData.XmlDoc:
				oraXmlTypeData.m_xmlStr = m_xmlDocInternal.OuterXml;
				oraXmlTypeData.m_typeOfXmlData = TypeOfXmlData.String;
				break;
			case TypeOfXmlData.Clob:
				oraXmlTypeData.m_xmlClob = (OracleClob)m_xmlClob.Clone();
				oraXmlTypeData.m_typeOfXmlData = TypeOfXmlData.Clob;
				break;
			case TypeOfXmlData.ClobAndString:
				oraXmlTypeData.m_xmlClob = (OracleClob)m_xmlClob.Clone();
				oraXmlTypeData.m_xmlStr = m_xmlStr;
				oraXmlTypeData.m_typeOfXmlData = TypeOfXmlData.ClobAndString;
				break;
			case TypeOfXmlData.BlobWithText:
				oraXmlTypeData.m_xmlBlobText = m_xmlBlobText.Clone();
				oraXmlTypeData.m_typeOfXmlData = TypeOfXmlData.BlobWithText;
				break;
			case TypeOfXmlData.BlobWithTextAndString:
				oraXmlTypeData.m_xmlBlobText = m_xmlBlobText.Clone();
				oraXmlTypeData.m_xmlStr = m_xmlStr;
				oraXmlTypeData.m_typeOfXmlData = TypeOfXmlData.BlobWithTextAndString;
				break;
			case TypeOfXmlData.BlobCSX:
				oraXmlTypeData.m_xmlBlobCSX = (OracleBlob)m_xmlBlobCSX.Clone();
				oraXmlTypeData.m_typeOfXmlData = TypeOfXmlData.BlobCSX;
				break;
			case TypeOfXmlData.BlobCSXAndString:
				oraXmlTypeData.m_xmlBlobCSX = (OracleBlob)m_xmlBlobCSX.Clone();
				oraXmlTypeData.m_xmlStr = m_xmlStr;
				oraXmlTypeData.m_typeOfXmlData = TypeOfXmlData.BlobCSXAndString;
				break;
			}
			return oraXmlTypeData;
		}
	}
}
